﻿using System;

namespace UFrame
{
    public class ConnectionAS : NetWork
    {
        private static ConnectionAS i = null;

        public static ConnectionAS I
        {
            get
            {
                if (i == null)
                {
                    i = new ConnectionAS();
                }

                return i;
            }
        }

        protected override void InitialProtocol()
        {
            //RegisterMsg((ushort)OpCode.login, "c_as.AllGameServerInfo", new ProtocolHandler(UI_Login.Instance.ServerEveLogin));
            //RegisterMsg((ushort)OpCode.chose_game_server, "c_as.ChoseCameServerACK", new ProtocolHandler(UI_Login.Instance.GetACK));
        }

        public void SendRPC(AsOpCode op)
        {
            SendRPC((ushort)op);

            //if (op != OpCode.heart_beat)
            //    Global.Log("send:" + op.ToString());
        }

        public void SendRPC<T>(AsOpCode op, T rpc)
        {
            SendRPC<T>((ushort)op, rpc);
        }

        protected override void OnConnected(object src, EventArgs arg)
        {
            PLDebug.Log("连接账号服务器成功");
            base.OnConnected(src, arg);
        }

        protected override void OnConnectFailed(object src, EventArgs arg)
        {
            PLDebug.Log("连接账号服务器失败");
            base.OnConnectFailed(src, arg);
        }

        protected override void OnDisconnected(object src, EventArgs arg)
        {
            PLDebug.Log("断开账号服务器");
            base.OnDisconnected(src, arg);
        }
    }

    public enum AsOpCode
    {
        Error = 0,
        Login = 1,
        Chose_game_server = 2
    }
}